<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>


// 创建图的函数
function createGraph() {
    const adjacencyList = {};

    // 添加节点
    function addNode(node) {
        if (!adjacencyList[node]) {
            adjacencyList[node] = [];
        }
    }

    // 添加边
    function addEdge(node1, node2) {
        if (!adjacencyList[node1]) {
            addNode(node1);
        }
        if (!adjacencyList[node2]) {
            addNode(node2);
        }
        adjacencyList[node1].push(node2);
        adjacencyList[node2].push(node1); // 如果是无向图
    }

    // 显示图的邻接列表
    function display() {
        for (const node in adjacencyList) {
            console.log(`${node} -> ${adjacencyList[node].join(', ')}`);
        }
    }

    return {
        addNode,
        addEdge,
        display
    };
}

// 使用示例
const graph = createGraph();
graph.addNode('A');
graph.addNode('B');
graph.addEdge('A', 'B');
graph.addEdge('A', 'C');
graph.addEdge('B', 'C');
graph.display();


    </script>
</body>
</html>